﻿@inject UserServices services
@{
    var node = ViewBag.Node as TopicNode;
    ViewData["Title"] = node.Name + "-.NET Core 跨平台论坛";
    var list = ViewBag.Topics as List<TopicViewModel>;
    var user = await services.User;
}
@model Topic

<div class="row">
    <div class="col-md-9 topics">
        <div class="panel panel-default">
            <div class="panel-heading clearfix">
                <div class="node-info">
                    <div class="name">
                        <strong>@node.Name</strong> <span class="total">共有 @ViewBag.Count 个讨论主题</span>
                    </div>
                    <div class="summary">
                        <p>@node.Name 讨论区</p>
                    </div>
                </div>
            </div>
            <div class="panel-body">
                @foreach (var item in list)
                {
                    <div class="topic">
                        <div class="avatar media-left">
                            <a href="#"><img class="avatar-48" src="@(string.IsNullOrEmpty(item.Avatar)?"/images/96.png": item.Avatar)" alt="96"></a>
                        </div>
                        <div class="media-body">
                            <div class="title">
                                <a asp-controller="Topic" asp-action="Index" asp-route-id="@item.Id">
                                    @(item.Top == 1 ? "[置顶]" : "")@item.Title
                                </a>
                            </div>
                            <div class="info">
                                <a href="/topic/node/@node.Id">@node.Name</a> 【<label>@item.UserName</label>】发布于 @item.CreateOn.ToString("MM-dd HH:mm")
                                @if (item.LastReplyTime != DateTime.MinValue)
                                {
                                    <label>最后回复 @item.LastReplyTime.ToString("MM-dd HH:mm")</label>
                                }
                            </div>
                        </div>
                        <div class="count media-right">
                            @if (item.ReplyCount > 0)
                            {
                                <a class="state-false" href="/Topic/@item.Id#reply@(item.ReplyCount)">@item.ReplyCount</a>
                            }
                        </div>
                    </div>
                }
            </div>
            <div class="panel-footer clearfix">
                @await Html.PartialAsync("_PagerPartial", ViewData)
            </div>
        </div>
        <div class="panel panel-default" style="padding:15px">
            @if (user != null)
            {
                <form class="form-horizontal" method="post" asp-controller="Home" asp-action="Index">
                    <input type="hidden" asp-for="NodeId" value="@(node.Id)" />
                    <div class="form-group">
                        <label for="inputTitle" class="col-sm-2 control-label">主题</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="inputTitle" placeholder="填写主题" required asp-for="Title">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">内容</label>
                        <div class="col-sm-10">
                            <textarea class="form-control" rows="10" asp-for="Content" placeholder="填写内容" id="editor" data-provide="markdown"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <input type="hidden" asp-for="UserId" value="@(user.Id)" />
                        <input type="hidden" asp-for="Email" value="@(user.Email)">
                        <div class="col-sm-offset-2 col-sm-10">
                            <button type="submit" class="btn btn-default">发布</button>
                        </div>
                    </div>
                </form>
            }
            else
            {
                <p>
                    需要<a asp-controller="Account" asp-action="Login" class="btn btn-primary">登录</a>发布新话题,
                    如果你还没有账号请点击这里 <a asp-controller="Account" asp-action="Register" class="btn btn-danger">注册</a>。
                </p>
            }
        </div>
    </div>
    <div class="col-md-3">
        @await Html.PartialAsync("_SidebarPartial")
    </div>
</div>
